package com.szt.mobile.inventory.reciver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

import com.szt.mobile.inventory.common.utils.ToastUtils;

/**
 * @author 刘育成
 * @package com.szt.mobile.inventory.Reciver
 * @fileName NetBroadCastReciver
 * @date or 2019/1/29 18:37
 * @describe TODO
 */
public class NetBroadCastReciver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //如果是在开启wifi连接和有网络状态下
        if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
            ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo info = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
            if (NetworkInfo.State.CONNECTED != info.getState()) {
                ToastUtils.getInstanc(context).showToast("网络连接失败");
            }
    }}
}
